﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FlightSystemDBLayer
{
  class SQLAccess
{
      
   ////private static final String  driver = "jdbc:sqlserver://localhost:1433";
   // private static final String  databaseName = ";databaseName=company";
//jdbc:sqlserver://localhost\SQLEXPRESS/Databases/EPS:1357;user=epsingall;password=welkom1;
      public static readonly string connectionString = @"Data Source=balder.ucn.dk; Initial Catalog=dmaai0913Group6; User ID=dmaai0913Group6; Password=IsAllowed;";
        public static readonly SqlConnection dbconn = new SqlConnection(connectionString);

        private static SqlCommand dbCmd;

        public static void Open()
        {
            if (dbconn.State.ToString().CompareTo("Open") != 0)
            {
                dbconn.Open();
                Console.WriteLine(dbconn.Database + "this");
            }
        }

        public static void Close()
        {
            dbconn.Close();
        }

        public static SqlCommand GetDbCommand(string sql)
        {
            if (dbconn.State.ToString().CompareTo("Open") != 0)
                Open();
            if (dbCmd == null)
            {
                dbCmd = new SqlCommand(sql, dbconn);
            }
            dbCmd.CommandText = sql;
            return dbCmd;
        }
    }
}

